let http = require('http');

let path = require('path');

let fs = require('fs');

http.createServer((req,res)=>{

    let url = req.url;

    if(url === '/'){
         // 读取文件
        fs.readFile(path.resolve(__dirname,'./index.html'),(err,data)=>{
            if(err){
                console.log(err);
                return;
            }
            res.end(data);
        });
    }else if(url === '/css/style.css'){
        fs.readFile(path.resolve(__dirname,'./css/style.css'),(err,data)=>{
            if(err){
                console.log(err);
                return;
            }
            res.end(data);
        });
    }
    else if(url === '/js/main.js'){
        fs.readFile(path.resolve(__dirname,'./js/main.js'),(err,data)=>{
            if(err){
                console.log(err);
                return;
            }
            res.end(data);
        });
    }else{
        res.end('<h1>404</h1>');
    }

}).listen(8080,()=>{
    console.log("8080启动成功");
});